<template>
    <div class="contract-list-page contract-cancellation-list">
        <Card>
            <CancellationForm
                :isSP="isSP"
                :formValidate="formValidate"
                :formValidateRule="formValidateRule"
                :dataDict="dataDict"
                @showModal="showModal"
                @getList="getList"
                :loading="loading"
            />
            <CancellationTable
                :isSP="isSP"
                :formValidate="formValidate"
                :dataDict="dataDict"
                :contractTable="contractTable"
                @getList="getList"
                @showContractDetial="showContractDetial"
            />
        </Card>
        <ActivatedCase
            :isSP="isSP"
            :getDataFn="getDataFn"
            :contractBusiness="contractBusiness"
            :handleBusiness="'cancelContract'"
            :dataDict="dataDict"
            :modal="modal"
            :modalTitle="modalTitle"
            @showContractDetial="showContractDetial"
            @closeModal="closeModal"
        />
    </div>
</template>
<script>
    // api
    import {
        findContractCancelList,
        getBasicCancelList,
        getBasicCancelLoanList
    } from "_p/basic/api/contract/contract-cancel/index";
    import {mapActions, mapGetters} from "vuex";
    import CancellationForm from "./CancellationForm";
    import CancellationTable from "./CancellationTable";
    import {getDictDataList} from "_p/basic/assets/contract/js/utils";
    import {isPhoneValiate} from "_p/basic/assets/contract/js/utils";
    import {channelType} from "_p/basic/api/contract/channel-type/channel-type";
    import ActivatedCase from "_p/basic/pages/contract/common/activated-case/index";

    export default {
        name: "ContractCancellationList",
        components: {
            CancellationForm,
            CancellationTable,
            ActivatedCase
        },
        props: {},
        data() {
            return {
                pageNo: 1,
                loading: false,
                // 日期区间
                isDateErr: false,
                contractBusiness: ["cancelContract", "closeContract"],
                formValidate: {
                    applyNo: "", // 申请编号
                    certNo: "", // 证件号码
                    contractNo: "", // 合同号
                    contractStatusEnum: null, // 合同状态 contractCancel

                    custName: "", // 客户名称
                    endDate: "", //合同到期时间  结束时间
                    startDate: "", //合同激活时间 申请时间
                    phone: "", //手机号码
                    pageNumber: 1, // integer($int32) // 当前页
                    pageSize: 10 //integer($int32) // 多少条
                },
                formValidateRule: {
                    phone: [
                        {
                            validator: (rule, value, callback) => {
                                isPhoneValiate(rule, value, callback);
                            },
                            trigger: "blur"
                        }
                    ]
                },

                contractTable: {
                    current: 1, // 表格当前页
                    pages: 0,
                    searchCount: false,
                    size: 10,
                    total: 0,
                    orders: [],
                    records: []
                },
                dicttArr: ["cancelProcessStatus", "businessSource", "PersonRoleType", "contractStatus", "channelBelong",
                    "creditStatus"],
                // selct 数据字典
                dataDict: {},
                modalTitle: "",
                modal: false
            };
        },
        computed: {
            ...mapGetters({
                userInfo: "userInfo",
                roleType: "roles",
            }),
            // 是否是合作商
            isSP: function () {
                return channelType(this.roleType)
                // return true;
            },
            getDataFn: function () {
                if (this.isSP) {
                    return getBasicCancelLoanList;
                } else {
                    return getBasicCancelList;
                }

            }
        },
        mounted() {
            this.init();
        },
        activated() {
            this.getList(this.formValidate);
        },
        methods: {
            ...mapActions(["getDictData"]),
            init() {
                // 数据字典
                this.getDictDataList();
            },
            getDictDataList() {
                getDictDataList(this.dicttArr).then(res => {
                    this.dataDict = res;
                });
            },
            getList(data) {
                this.loading = true;
                findContractCancelList(data).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.contractTable = res.data;
                    } else {
                        this.$Message.error("Fail!");
                    }
                }).catch(e => {
                    this.loading = false;
                });
            },
            // 弹窗
            showModal() {
                this.modalTitle = "已激活案件列表";
                this.modal = true;
            },
            closeModal() {
                this.modal = false;
            },
            showContractDetial(params) {
                // let id = params.contractNo ? params.contractNo : "0";
                params.editFlag = false;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/contract-cancellation/contract-cancellation-detial/index",
                    "合同取消详情",
                    "ios-add",
                    params,
                    "contract-cancellation-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            }
        },
    };
</script>
<style lang="less">
    @import "../../../../styles/common/form.less";

</style>
